//  vue.config.js
// eslint-disable-next-line no-unused-vars
const path = require('path');

module.exports = {
    publicPath: '/', // 默认'/'，部署应用包时的基本 URL
    outputDir: 'dist', // 默认'dist', 生产环境构建文件的目录
    assetsDir: '', // 相对于outputDir的静态资源(js、css、img、fonts)目录
    lintOnSave: false, // 是否使用eslint
    productionSourceMap: false, // 生产环境的 source map
    configureWebpack: config => {
        if (process.env.NODE_ENV === 'production') {
            config.optimization.minimizer[0].options.terserOptions.compress.warnings = false; // 去除warning警告
            config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true; // 去除debugger
            config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = [
                'console.log',
                'console.warn'
            ];
            config.optimization.minimizer[0].options.terserOptions.compress.dead_code = true; // 去除不可达代码
            config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true; //去除console
        }
    },
    chainWebpack: config => {
        config.entry('index').add('babel-polyfill').end();
    },
    devServer: {
        host: 'localhost',//target host
        port: 8888, // 端口号
        overlay: {
            warnings: true,
            error: true
        },
        proxy: {
            // https://www.easy-mock.com/mock/5df1c1e5d0843e1ef18f6fcf/testApi/user/dav/list
            '/testApi': {
                target: 'https://www.easy-mock.com/mock/5df1c1e5d0843e1ef18f6fcf',//代理地址，这里设置的地址会代替axios中设置的baseURL
                changeOrigin: true,// 如果接口跨域，需要进行这个参数配置
                ws: true,// proxy websockets
                //pathRewrite方法重写url
                pathRewrite: {
                    //pathRewrite: {'^/api': '/'} 重写之后url为 http://192.168.1.16:9002/xxxx
                    //pathRewrite: {'^/api': '/api'} 重写之后url为 http://192.168.1.16:9002/api/xxxx
                    '^/testApi': ''
                }
            }
        }
    }
};
